<?php
define('EZSITETPL_SOAP', 1);
include_once('config.php');
include_once('func_utils.php');

define('DS', DIRECTORY_SEPARATOR);
define('ROOT', dirname(__FILE__));
define('P_TPL', realpath(ROOT.DS.'../..'.DS.'templates/template_jingjian'));
define('PRE_SCRSHOT_URL', _urlprefix().URL_SCRSHOT);
define('PRE_DOWNLOAD_URL', _urlprefix().URL_DOWNLOAD);

$db = mysqli_connect(DB_HOST, DB_USER, DB_PASS);
mysqli_set_charset($db, DB_CHAR);
mysqli_select_db($db, DB_NAME);
$cates = array();

$sql = <<<SQL
SELECT * FROM ezsite_template_new_categories AS etc
INNER JOIN 
(
SELECT COUNT(*) AS amount,ezsite_template_category_id FROM ezsite_new_templates WHERE i_level = 2
GROUP BY ezsite_template_category_id
) et
ON etc.id = et.ezsite_template_category_id
SQL;
$rs =  mysqli_query($db, $sql);

if ($rs && mysqli_num_rows($rs) > 0) {
	while ($row = mysqli_fetch_assoc($rs)) {
		 $cates[] = $row;
    }
}
mysqli_free_result($rs);
echo serialize($cates);

?>